/*
 * Copyright (C) 2015 The Gravitee team (http://gravitee.io)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
import { ConnectorListItem } from './connector-list-item';

export function fakeConnectorListItem(modifier?: Partial<ConnectorListItem>): ConnectorListItem {
  const base: ConnectorListItem = {
    id: 'connector-http',
    name: 'HTTP Connector',
    description: 'The Gravitee.IO Parent POM provides common settings for all Gravitee components.',
    version: '2.0.6',
    schema:
      '{\n  "type": "object",\n  "id": "urn:jsonschema:io:gravitee:connector:http:configuration:HttpConnectorConfiguration",\n  "properties": {\n    "http": {\n      "type": "object",\n      "title": "HTTP Options",\n      "id": "urn:jsonschema:io:gravitee:connector:http:configuration:HttpOptions",\n      "properties": {\n        "version": {\n          "title": "HTTP Protocol version",\n          "description": "The version of the HTTP protocol to use",\n          "type": "string",\n          "default": "HTTP_1_1",\n          "enum": ["HTTP_1_1", "HTTP_2"],\n          "x-schema-form": {\n            "type": "select",\n            "titleMap": {\n              "HTTP_1_1": "HTTP 1.1",\n              "HTTP_2": "HTTP 2"\n            }\n          }\n        },\n        "keepAlive": {\n          "title": "Enable keep-alive",\n          "description": "Use an HTTP persistent connection to send and receive multiple HTTP requests / responses.",\n          "type": "boolean",\n          "default": true\n        },\n        "connectTimeout": {\n          "type": "integer",\n          "title": "Connect timeout (ms)",\n          "description": "Maximum time to connect to the remote host.",\n          "default": 5000\n        },\n        "pipelining": {\n          "title": "Enable HTTP pipelining",\n          "description": "When pipe-lining is enabled requests will be written to connections without waiting for previous responses to return.\\n",\n          "type": "boolean",\n          "default": false\n        },\n        "readTimeout": {\n          "type": "integer",\n          "title": "Read timeout (ms)",\n          "description": "Maximum time to complete the request (including response).",\n          "default": 10000\n        },\n        "useCompression": {\n          "title": "Enable compression (gzip, deflate)",\n          "description": "The gateway can let the remote http server know that it supports compression, and will be able to handle compressed response bodies.",\n          "type": "boolean",\n          "default": true\n        },\n        "idleTimeout": {\n          "type": "integer",\n          "title": "Idle timeout (ms)",\n          "description": "Maximum time a connection will timeout and be closed if no data is received within the timeout.",\n          "default": 60000\n        },\n        "followRedirects": {\n          "title": "Follow HTTP redirects",\n          "description": "When the client receives a status code in the range 3xx, it follows the redirection provided by the Location response header",\n          "type": "boolean",\n          "default": false\n        },\n        "maxConcurrentConnections": {\n          "type": "integer",\n          "title": "Max Concurrent Connections",\n          "description": "Maximum pool size for connections.",\n          "default": 100\n        },\n        "clearTextUpgrade": {\n          "title": "Allow h2c Clear Text Upgrade",\n          "description": "If enabled, an h2c connection is established using an HTTP/1.1 Upgrade request. If disabled, h2c connection is established directly (with prior knowledge) ",\n          "type": "boolean",\n          "default": true,\n          "x-schema-form": {\n            "hidden": [\n              {\n                "$eq": {\n                  "http.version": "HTTP_1_1"\n                }\n              }\n            ]\n          }\n        }\n      },\n      "required": ["connectTimeout", "readTimeout", "idleTimeout", "maxConcurrentConnections"]\n    },\n    "headers": {\n      "type": "array",\n      "title": "HTTP Headers",\n      "description": "Default HTTP headers added or overrided by the API gateway to upstream",\n      "items": {\n        "type": "object",\n        "title": "Header",\n        "id": "urn:jsonschema:io:gravitee:connector:http:configuration:HttpHeader",\n        "properties": {\n          "name": {\n            "type": "string",\n            "title": "Name"\n          },\n          "value": {\n            "type": "string",\n            "title": "Value"\n          }\n        },\n        "required": ["name", "value"]\n      }\n    },\n    "proxy": {\n      "type": "object",\n      "title": "Proxy Options",\n      "id": "urn:jsonschema:io:gravitee:connector:http:configuration:HttpProxyOptions",\n      "properties": {\n        "enabled": {\n          "type": "boolean",\n          "title": "Use proxy",\n          "description": "Use proxy for client connections",\n          "default": false\n        },\n        "type": {\n          "type": "string",\n          "title": "Proxy Type",\n          "description": "The type of the proxy",\n          "default": "HTTP",\n          "enum": ["HTTP", "SOCKS4", "SOCKS5"],\n          "x-schema-form": {\n            "type": "select",\n            "titleMap": {\n              "HTTP": "HTTP CONNECT proxy",\n              "SOCKS4": "SOCKS4/4a tcp proxy",\n              "SOCKS5": "SOCKS5 tcp proxy"\n            },\n            "hidden": [\n              {\n                "$eq": {\n                  "proxy.enabled": false\n                }\n              }\n            ],\n            "disabled": [\n              {\n                "$eq": {\n                  "proxy.useSystemProxy": true\n                }\n              }\n            ]\n          }\n        },\n        "useSystemProxy": {\n          "type": "boolean",\n          "title": "Use system proxy",\n          "description": "Use proxy configured at system level",\n          "default": false,\n          "x-schema-form": {\n            "hidden": [\n              {\n                "$eq": {\n                  "proxy.enabled": false\n                }\n              }\n            ]\n          }\n        },\n        "host": {\n          "type": "string",\n          "title": "Proxy host",\n          "description": "Proxy host to connect to",\n          "x-schema-form": {\n            "hidden": [\n              {\n                "$eq": {\n                  "proxy.enabled": false\n                }\n              }\n            ],\n            "disabled": [\n              {\n                "$eq": {\n                  "proxy.useSystemProxy": true\n                }\n              }\n            ]\n          }\n        },\n        "port": {\n          "type": "integer",\n          "title": "Proxy port",\n          "description": "Proxy port to connect to",\n          "x-schema-form": {\n            "hidden": [\n              {\n                "$eq": {\n                  "proxy.enabled": false\n                }\n              }\n            ],\n            "disabled": [\n              {\n                "$eq": {\n                  "proxy.useSystemProxy": true\n                }\n              }\n            ]\n          }\n        },\n        "username": {\n          "type": "string",\n          "title": "Proxy username",\n          "description": "Optional proxy username",\n          "x-schema-form": {\n            "hidden": [\n              {\n                "$eq": {\n                  "proxy.enabled": false\n                }\n              }\n            ],\n            "disabled": [\n              {\n                "$eq": {\n                  "proxy.useSystemProxy": true\n                }\n              }\n            ]\n          }\n        },\n        "password": {\n          "type": "string",\n          "title": "Proxy password",\n          "description": "Optional proxy password",\n          "x-schema-form": {\n            "type": "password",\n            "hidden": [\n              {\n                "$eq": {\n                  "proxy.enabled": false\n                }\n              }\n            ],\n            "disabled": [\n              {\n                "$eq": {\n                  "proxy.useSystemProxy": true\n                }\n              }\n            ]\n          }\n        }\n      },\n      "oneOf": [\n        {\n          "properties": { "enabled": { "const": false } }\n        },\n        {\n          "properties": { "useSystemProxy": { "const": true } }\n        },\n        {\n          "properties": { "enabled": { "const": true }, "useSystemProxy": { "const": false } },\n          "required": ["host", "port"]\n        }\n      ]\n    },\n    "ssl": {\n      "type": "object",\n      "title": "SSL Options",\n      "id": "urn:jsonschema:io:gravitee:connector:http:configuration:SslOptions",\n      "properties": {\n        "hostnameVerifier": {\n          "title": "Verify Host",\n          "description": "Use to enable host name verification",\n          "type": "boolean",\n          "default": false\n        },\n        "trustAll": {\n          "title": "Trust all",\n          "description": "Use this with caution (if over Internet). The gateway must trust any origin certificates. The connection will still be encrypted but this mode is vulnerable to \'man in the middle\' attacks.",\n          "type": "boolean",\n          "default": false\n        },\n        "trustStore": {\n          "type": "object",\n          "title": "Trust store",\n          "id": "urn:jsonschema:io:gravitee:connector:http:configuration:SslTrustStoreOptions",\n          "properties": {\n            "type": {\n              "type": "string",\n              "title": "Type",\n              "description": "The type of the trust store",\n              "default": "",\n              "enum": ["", "JKS", "PKCS12", "PEM"],\n              "x-schema-form": {\n                "type": "select",\n                "titleMap": {\n                  "": "None",\n                  "JKS": "Java Trust Store (.jks)",\n                  "PKCS12": "PKCS#12 (.p12) / PFX (.pfx)",\n                  "PEM": "PEM (.pem)"\n                }\n              }\n            },\n            "password": {\n              "type": "string",\n              "title": "Password",\n              "description": "Trust store password",\n              "x-schema-form": {\n                "type": "password",\n                "hidden": [\n                  {\n                    "$eq": {\n                      "ssl.trustStore.type": ["", "PEM"]\n                    }\n                  }\n                ]\n              }\n            },\n            "path": {\n              "type": "string",\n              "title": "Path to trust store",\n              "description": "Path to the trust store file",\n              "x-schema-form": {\n                "hidden": [\n                  {\n                    "$eq": {\n                      "ssl.trustStore.type": ""\n                    }\n                  }\n                ]\n              }\n            },\n            "content": {\n              "type": "string",\n              "title": "Content",\n              "description": "Binary content as Base64",\n              "x-schema-form": {\n                "type": "text",\n                "hidden": [\n                  {\n                    "$eq": {\n                      "ssl.trustStore.type": ""\n                    }\n                  }\n                ]\n              }\n            }\n          },\n          "oneOf": [\n            {\n              "properties": { "type": { "const": "" } }\n            },\n            {\n              "properties": { "type": { "const": "PEM" } },\n              "required": ["content"]\n            },\n            {\n              "properties": { "type": { "const": "PEM" } },\n              "required": ["path"]\n            },\n            {\n              "properties": { "type": { "pattern": "JKS|PKCS12" } },\n              "required": ["content", "password"]\n            },\n            {\n              "properties": { "type": { "pattern": "JKS|PKCS12" } },\n              "required": ["path", "password"]\n            }\n          ],\n          "x-schema-form": {\n            "hidden": [\n              {\n                "$eq": {\n                  "ssl.trustAll": true\n                }\n              }\n            ]\n          }\n        },\n        "keyStore": {\n          "type": "object",\n          "title": "Key store",\n          "id": "urn:jsonschema:io:gravitee:connector:http:configuration:SslKeyStoreOptions",\n          "properties": {\n            "type": {\n              "type": "string",\n              "title": "Type",\n              "description": "The type of the key store",\n              "default": "",\n              "enum": ["", "JKS", "PKCS12", "PEM"],\n              "x-schema-form": {\n                "type": "select",\n                "titleMap": {\n                  "": "None",\n                  "JKS": "Java Trust Store (.jks)",\n                  "PKCS12": "PKCS#12 (.p12) / PFX (.pfx)",\n                  "PEM": "PEM (.pem)"\n                }\n              }\n            },\n            "password": {\n              "type": "string",\n              "title": "Password",\n              "description": "Key store password",\n              "x-schema-form": {\n                "type": "password",\n                "hidden": [\n                  {\n                    "$eq": {\n                      "ssl.keyStore.type": ["", "PEM"]\n                    }\n                  }\n                ]\n              }\n            },\n            "path": {\n              "type": "string",\n              "title": "Path to key store",\n              "description": "Path to the key store file",\n              "x-schema-form": {\n                "hidden": [\n                  {\n                    "$eq": {\n                      "ssl.keyStore.type": ["", "PEM"]\n                    }\n                  }\n                ]\n              }\n            },\n            "content": {\n              "type": "string",\n              "title": "Content",\n              "description": "Binary content as Base64",\n              "x-schema-form": {\n                "type": "text",\n                "hidden": [\n                  {\n                    "$eq": {\n                      "ssl.keyStore.type": ["", "PEM"]\n                    }\n                  }\n                ]\n              }\n            },\n            "certPath": {\n              "type": "string",\n              "title": "Path to cert file",\n              "description": "Path to cert file (.PEM)",\n              "x-schema-form": {\n                "hidden": [\n                  {\n                    "$neq": {\n                      "ssl.keyStore.type": "PEM"\n                    }\n                  }\n                ]\n              }\n            },\n            "certContent": {\n              "type": "string",\n              "title": "Certificate",\n              "x-schema-form": {\n                "type": "text",\n                "hidden": [\n                  {\n                    "$neq": {\n                      "ssl.keyStore.type": "PEM"\n                    }\n                  }\n                ]\n              }\n            },\n            "keyPath": {\n              "type": "string",\n              "title": "Path to private key file",\n              "description": "Path to private key file (.PEM)",\n              "x-schema-form": {\n                "hidden": [\n                  {\n                    "$neq": {\n                      "ssl.keyStore.type": "PEM"\n                    }\n                  }\n                ]\n              }\n            },\n            "keyContent": {\n              "type": "string",\n              "title": "Private key",\n              "x-schema-form": {\n                "type": "text",\n                "hidden": [\n                  {\n                    "$neq": {\n                      "ssl.keyStore.type": "PEM"\n                    }\n                  }\n                ]\n              }\n            }\n          },\n          "oneOf": [\n            {\n              "properties": { "type": { "const": "" } }\n            },\n            {\n              "properties": { "type": { "const": "PEM" } },\n              "required": ["certContent", "keyContent"]\n            },\n            {\n              "properties": { "type": { "const": "PEM" } },\n              "required": ["certPath", "keyPath"]\n            },\n            {\n              "properties": { "type": { "const": "PEM" } },\n              "required": ["certContent", "keyPath"]\n            },\n            {\n              "properties": { "type": { "const": "PEM" } },\n              "required": ["certPath", "keyContent"]\n            },\n            {\n              "properties": { "type": { "pattern": "JKS|PKCS12" } },\n              "required": ["content", "password"]\n            },\n            {\n              "properties": { "type": { "pattern": "JKS|PKCS12" } },\n              "required": ["path", "password"]\n            }\n          ]\n        }\n      }\n    }\n  },\n  "additionalProperties": false,\n  "patternProperties": {\n    "backup": true,\n    "healthcheck": true,\n    "inherit": true,\n    "name": true,\n    "target": true,\n    "tenants": true,\n    "type": true,\n    "weight": true\n  },\n  "x-schema-form": {\n    "errors": {\n      "proxy": {\n        "oneOf": "The host and port are <span class=\\"error\\">required</span>"\n      },\n      "ssl": {\n        "trustStore": {\n          "oneOf": "A path or a content is <span class=\\"error\\">required</span> - for JKS and PKCS#12 a password is also <span class=\\"error\\">required</span>"\n        },\n        "keyStore": {\n          "oneOf": "Paths or contents are <span class=\\"error\\">required</span> - for JKS and PKCS#12, a password is also <span class=\\"error\\">required</span>."\n        }\n      }\n    }\n  }\n}\n',
    supportedTypes: ['http', 'grpc'],
    supportedApiType: 'proxy',
    supportedListenerType: 'http',
  };

  return {
    ...base,
    ...modifier,
  };
}
